//
//  WBNavViewController.swift
//  SinaWebo
//
//  Created by 亚杏 on 2017/5/5.
//  Copyright © 2017年 oms. All rights reserved.
//

import UIKit

class WBNavViewController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //隐藏默认的NavBar
        navigationBar.isHidden = true


    }

    //重写push方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {

        //隐藏底部tabbar
        //如果不是栈底控制器才需要隐藏，根控制器不需要处理
        if childViewControllers.count>0 {
            viewController.hidesBottomBarWhenPushed = true

            //push时，设置他的左侧返回按钮
            if let vc = viewController as? WBBaseViewController{

                var title = "返回"
                //判断控制器级数，
                //只有一个子控制器时，显示栈底控制器标题，即baritem自动的首页标题
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }

                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToLastVC),isBackBtn:true)
            }
        }

        super.pushViewController(viewController, animated: true)
    }

    @objc private func popToLastVC(){
        popViewController(animated: true)

    }
    

}
